package com.spring;

import com.spring.config.MyConfig;
import com.spring.entity.UserEntity;
import com.spring.service.UserService;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class Application {

    public static void main(String[] args) {
        // 解析xml配置，并指定xml文件，xml文件默认在resource根目录下
//        ClassPathXmlApplicationContext classPathXmlApplicationContext = new ClassPathXmlApplicationContext("application.xml");
//        // 获取对象
//        UserEntity userEntity = classPathXmlApplicationContext.getBean("userEntity", UserEntity.class);
//        System.out.println(userEntity.toString());

        // 扫描注解
        AnnotationConfigApplicationContext annotationConfigApplicationContext = new AnnotationConfigApplicationContext(MyConfig.class);
        // 获取在MyConfig中注入的所有bean
//        String[] beanDefinitionNames = annotationConfigApplicationContext.getBeanDefinitionNames();
//        for (int i = 0; i < beanDefinitionNames.length; i++) {
//            System.out.println(beanDefinitionNames[i]);
//        }
//        UserEntity userEntity1 = annotationConfigApplicationContext.getBean("userEntity", UserEntity.class);
//        System.out.println(userEntity1);
//        UserService userService1 = annotationConfigApplicationContext.getBean("userService", UserService.class);
//        UserService userService2 = annotationConfigApplicationContext.getBean("userService", UserService.class);
//        System.out.println(userService1 == userService2);
        System.out.println("配置文件启动成功");
        UserService userService1 = annotationConfigApplicationContext.getBean("userService", UserService.class);
    }

}
